<template>
  <div>
    <div class="nav">
      <router-link to="/index">
        <h3>取消</h3>
      </router-link>
      <nav class="search">
        <input type="text" placeholder="知晓从这里开始" v-model="value" @change="int1" />
        <a-icon type="search" @click="onsearch" />
      </nav>
    </div>
    <div v-if="show">

      <ul class="ul" >
        <div>
          {{ newData.articleId }}
          <li v-for="(item, index) in newData" :key="index" class="list">
            <router-link :to="{path:'/newsDetail',query:{articleId:item.articleId}}" class="href">
              <div class="pic">
                <img :src="item.bannerImgUrl" alt />
              </div>
              <div class="text">
                <p>{{ item.title }}</p>
                <span>{{ item.articleSource }}</span>
                <br />
                <span>{{ item.sendTime }}</span>
              </div>
            </router-link>
          </li>
        </div>
      </ul>

    </div>


    <div v-else>
      <!-- <div class="history">
        <span>搜索历史</span>
        <van-icon name="delete" />
      </div>-->
      <div class="historyBox"></div>
      <h2>热门看点</h2>
      <ul class="hotdot">
        <li v-for="(item, index) in list" :key="index"><router-link :to="{path:'/newsDetail',query:{articleId:item.articleId}}">
          {{ index + 1 }} {{ item.title }}
        </router-link>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
// import { getsearch, newDetail } from "../api/api";
import { hotNews } from "../api/api";
import { getsearch } from "../api/api";
export default {
  data() {
    return {
      list: [],
      data: [],
      newData: [],
      value: "",
      show: false,
    };
  },
  //   computed: {
  //     if(value=0){
  //         // this.newData
  //     }
  //   },
  created() {
    hotNews().then((res) => {
      this.list = res.rows;
    });
  },
  methods: {
    onsearch() {
      var allowpass = true;
      if (!allowpass) {
        return;
      }
      setTimeout(() => {
        allowpass = false;
        getsearch(this.value).then((res) => {
          this.newData = res.rows;
          this.show = true;
        });
      }, 200);
    },
    int1() {
      // console.log(this.value)
      if (this.value == "") {
        this.newsData = [];
        this.show = false;
      }
    },
    created() {},
  },
};
</script>

<style  scoped lang="less">
* {
  padding: 0;
  margin: 0;
}
.nav {
  width: 100%;
  display: flex;
  justify-content: space-around;
  padding: 15px 6px;
  background: #00aaff;
  color: white;
  .search {
    border: 1px solid #ccc;
    border-radius: 10px;
    padding-left: 20px;
    margin-top: 4px;
    width: 75%;
    input {
      width: 85%;
      background: #00aaff;
      outline: none;
      border: none;
    }
  }
}
.ul {
  //   height: 120px;
  overflow: auto;
}
.list {
  width: 100%;
  height: 120px;
  display: flex;
  padding: 10px;
  box-sizing: border-box;
  .href{
    display: flex;

    .pic {
      width: 40%;
      height: 100%;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .text {
      width: 50%;
      margin-left: 20px;
      p {
        color: black;
        font-size: 16px;
      }
      span {
        color: #aaa;
        font-size: 12px;
      }
    }
  }
}
.history {
  width: 100%;
}
.historyBox {
  width: 100%;
  //   height: 100px;
  // background-color: red;
  margin-bottom: 20px;
}
.hotdot {
  width: 320px;
  // height: 500px;
  margin: 20px auto;
  li {
    width: 100%;
    height: 20px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    margin-top: 10px;
  }
}
</style>
